package GUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

import Client.Client;

@SuppressWarnings("serial")
public class JournalFrame extends JFrame implements ActionListener {
        JTextField input;
        JButton requestButton, editButton, createButton, removeButton;
        Client client;

        public JournalFrame(Client client) {

                super("Journal Handler");
                setVisible(true);
                this.setSize(500, 100);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.client = client;

                setLayout(new GridLayout(5, 1));

                // lägg till saker i listan;

                input = new JTextField("");
                add(input);

                requestButton = new JButton("Request journal");
                add(requestButton);

                editButton = new JButton("Edit journal");
                add(editButton);

                createButton = new JButton("Create journal");
                add(createButton);

                removeButton = new JButton("Remove journal");
                add(removeButton);

                requestButton.addActionListener(this);
                editButton.addActionListener(this);
                createButton.addActionListener(this);
                removeButton.addActionListener(this);

                pack();

        }

        @Override
        public void actionPerformed(ActionEvent e) {
              if (e.getSource() == requestButton) {
                      client.sendText("get_j","doc1","nurse1","a comment","123456");
                      String ds = client.listen();
                      new ShowFrame(client, ds);

              		this.setVisible(false);
              }
      		
              if (e.getSource() == editButton) {
                  client.sendText("get_j","doc1","nurse1","a comment","123456");
                  String ds = client.listen();
                  new EditFrame(client, ds);

          		this.setVisible(false);
              }
              if (e.getSource() == createButton) {
            	  client.sendText("get_j","doc1","nurse1","a comment","123456");
                  String ds = client.listen();
                  new EditFrame(client, ds);

          		this.setVisible(false);
              }
              if (e.getSource() == removeButton) {
            	  client.sendText("get_j","doc1","nurse1","a comment","123456");
            	  String ds = client.listen();
          		this.setVisible(false);
              }


        }

        public void warningMessage(String s) {
                System.out.print(s);
        }

}